package com.lwc.cfdns.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwc.cfdns.pojo.entity.SystemAdminDept;
import com.lwc.cfdns.pojo.entity.SystemAdminRole;
import com.lwc.cfdns.service.SystemAdminDeptService;
import com.lwc.cfdns.mapper.SystemAdminDeptMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author spring
 * @description 针对表【cfdns_system_admin_dept(用户和部门关联表(用户1-N部门))】的数据库操作Service实现
 * @createDate 2023-05-26 11:41:55
 */
@Service
public class SystemAdminDeptServiceImpl extends ServiceImpl<SystemAdminDeptMapper, SystemAdminDept>
        implements SystemAdminDeptService {

    /**
     * 管理员部门关系
     *
     * @param id
     * @param depts
     * @return void
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/26 13:50:08
     */
    @Override
    public boolean depts(Long id, List<Long> depts) {
        this.baseMapper.delete(new LambdaQueryWrapper<SystemAdminDept>().eq(SystemAdminDept::getAdminId, id));
        if (depts.size() > 0) {
            List<SystemAdminDept> batInsert = new ArrayList<>();
            for (Long dept_id : depts) {
                SystemAdminDept systemAdminDept = new SystemAdminDept();
                systemAdminDept.setAdminId(id);
                systemAdminDept.setDeptId(dept_id);
                batInsert.add(systemAdminDept);
            }
            this.saveBatch(batInsert);
        }
        return false;
    }

    /**
     * 查询部门下的用户
     *
     * @param deptId
     * @return List<Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/29 21:44
     */
    @Override
    public List<Object> getAdminIds(Long deptId) {
        System.out.println(deptId);
        List<Object> admin_ids = this.baseMapper.selectObjs(new LambdaQueryWrapper<SystemAdminDept>().eq(SystemAdminDept::getDeptId, deptId).select(SystemAdminDept::getAdminId));
        return admin_ids;
    }
}




